package com.aiyige.page.publish.info.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.aiyige.location.model.LocationData;
import com.aiyige.page.publish.selecttag.model.SelectTagItem;
import com.aiyige.page.publish.tag.model.TagItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhuyakun on 2017/11/16.
 */

public class PublishInfoData implements Parcelable {
    String coverUrl;
    String title;
    List<ContentItem> contentItemList;


    public PublishInfoData() {
    }

    private PublishInfoData(Builder builder) {
        setCoverUrl(builder.coverUrl);
        setTitle(builder.title);
        setContentItemList(builder.contentItemList);
    }

    public static Builder newBuilder() {
        return new Builder();
    }


    public static class ContentItem implements Parcelable {
        String text;
        String imageUrl;
        int type;
        int textStyle;

        private ContentItem(Builder builder) {
            setText(builder.text);
            setImageUrl(builder.imageUrl);
            setType(builder.type);
            setTextStyle(builder.textStyle);
        }

        public static Builder newBuilder() {
            return new Builder();
        }

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }

        public String getImageUrl() {
            return imageUrl;
        }

        public void setImageUrl(String imageUrl) {
            this.imageUrl = imageUrl;
        }

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        public int getTextStyle() {
            return textStyle;
        }

        public void setTextStyle(int textStyle) {
            this.textStyle = textStyle;
        }


        public static final class Builder {
            private String text;
            private String imageUrl;
            private int type;
            private int textStyle;

            private Builder() {
            }

            public Builder text(String text) {
                this.text = text;
                return this;
            }

            public Builder imageUrl(String imageUrl) {
                this.imageUrl = imageUrl;
                return this;
            }

            public Builder type(int type) {
                this.type = type;
                return this;
            }

            public Builder textStyle(int textStyle) {
                this.textStyle = textStyle;
                return this;
            }

            public ContentItem build() {
                return new ContentItem(this);
            }
        }


        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(this.text);
            dest.writeString(this.imageUrl);
            dest.writeInt(this.type);
            dest.writeInt(this.textStyle);
        }

        protected ContentItem(Parcel in) {
            this.text = in.readString();
            this.imageUrl = in.readString();
            this.type = in.readInt();
            this.textStyle = in.readInt();
        }

        public static final Creator<ContentItem> CREATOR = new Creator<ContentItem>() {
            @Override
            public ContentItem createFromParcel(Parcel source) {
                return new ContentItem(source);
            }

            @Override
            public ContentItem[] newArray(int size) {
                return new ContentItem[size];
            }
        };
    }

    public String getCoverUrl() {
        return coverUrl;
    }

    public void setCoverUrl(String coverUrl) {
        this.coverUrl = coverUrl;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public List<ContentItem> getContentItemList() {
        return contentItemList;
    }

    public void setContentItemList(List<ContentItem> contentItemList) {
        this.contentItemList = contentItemList;
    }

    public static final class Builder {
        private String coverUrl;
        private String title;
        private List<ContentItem> contentItemList;

        private Builder() {
        }

        public Builder coverUrl(String coverUrl) {
            this.coverUrl = coverUrl;
            return this;
        }

        public Builder title(String title) {
            this.title = title;
            return this;
        }

        public Builder contentItemList(List<ContentItem> contentItemList) {
            this.contentItemList = contentItemList;
            return this;
        }

        public PublishInfoData build() {
            return new PublishInfoData(this);
        }
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.coverUrl);
        dest.writeString(this.title);
        dest.writeTypedList(this.contentItemList);
    }

    protected PublishInfoData(Parcel in) {
        this.coverUrl = in.readString();
        this.title = in.readString();
        this.contentItemList = in.createTypedArrayList(ContentItem.CREATOR);
    }

    public static final Parcelable.Creator<PublishInfoData> CREATOR = new Parcelable.Creator<PublishInfoData>() {
        @Override
        public PublishInfoData createFromParcel(Parcel source) {
            return new PublishInfoData(source);
        }

        @Override
        public PublishInfoData[] newArray(int size) {
            return new PublishInfoData[size];
        }
    };
}
